//
//  PersonalCenterViewController.m
//  HeWeiZhiNeng
//
//  Created by 林建 on 17/12/1.
//  Copyright © 2017年 YanCeyMichael.github.io. All rights reserved.
//

#import "PersonalCenterViewController.h"
#import "SpeechSettingViewController.h"
#import "LoginViewController.h"
#import "PersonCenterHeadView.h"
#import "TitleTableViewCell.h"

@interface PersonalCenterViewController ()<UITableViewDelegate,UITableViewDataSource,PersonCenterHeadViewDelegate>
@property (nonatomic, strong)UITableView *personTableView;
@property (nonatomic, strong)PersonCenterHeadView *headView;
@property (nonatomic, strong)NSMutableArray *perosnArr;
@end

@implementation PersonalCenterViewController
-(NSMutableArray *)perosnArr{
    if (!_perosnArr) {
        NSMutableArray *arr1  = [NSMutableArray arrayWithObjects:@{@"title":@"语音设置",@"img":@"cbl_yuyin"},@{@"title":@"子账号设置",@"img":@"cbl_zizhanghao"}, nil];
        NSMutableArray *arr2  = [NSMutableArray arrayWithObjects:@{@"title":@"退出登录",@"img":@"cbl_tuichu"}, nil];
        _perosnArr = [NSMutableArray arrayWithObjects:arr1, arr2, nil];
    }
    return _perosnArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = white_;
    [self.view addSubview:self.personTableView];
    [self.personTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    self.personTableView.tableHeaderView = self.headView;
    // Do any additional setup after loading the view.
}

#pragma mark ----- 创建个人中心视图 -----
-(PersonCenterHeadView *)headView{
    if (!_headView) {
        _headView = [[PersonCenterHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 228)];
        _headView.delegate = self;
    }
    return _headView;
}

#pragma mark ----- 头视图协议方法 -----
- (void)userChoose:(NSInteger)tag {
    switch (tag) {
        case 9999:
            [self GotoLoginView];
            break;
            
        default:
            break;
    }
}

#pragma mark ----- 跳转登录 -----
-(void)GotoLoginView{
    LoginViewController *loginVC = [[LoginViewController alloc]init];
    RTRootNavigationController *naVC = [[RTRootNavigationController alloc] initWithRootViewController:loginVC];
    [self presentViewController:naVC animated:YES completion:nil];
}

#pragma mark - tableView
#pragma mark ----- 创建个人中心tableView视图 -----
-(UITableView *)personTableView{
    if (!_personTableView) {
        _personTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _personTableView.backgroundColor = Color.back;
        _personTableView.scrollEnabled = NO;
        _personTableView.delegate = self;
        _personTableView.dataSource = self;
        _personTableView.showsVerticalScrollIndicator = NO;
        _personTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_personTableView registerClass:[TitleTableViewCell class] forCellReuseIdentifier:@"titleCell"];
    }
    return _personTableView;
}

#pragma mark ----- tableView的协议方法 -----
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.perosnArr[section] count];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.perosnArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"titleCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary *dic = self.perosnArr[indexPath.section][indexPath.row];
    cell.titleLabel.text = dic[@"title"];
    cell.MainView.image = [UIImage imageNamed:dic[@"img"]];
    if (indexPath.section == 0 && indexPath.row == 0) {
        cell.lineV.hidden = NO;
    } else {
        cell.lineV.hidden = YES;
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        SpeechSettingViewController *setVC = [[SpeechSettingViewController alloc]init];
        [self.navigationController pushViewController:setVC animated:YES];
    }
}

//section底部间距
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 15;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenW, 1)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
